import { transSea, exportMessage, handleCall } from "@/api/crm/customer.js";
import { Message } from "element-ui";

// 更改类型
export function subChangeType(form, category) {
  transSea(form, category).then(res => {
    if (res.code === 200) {
      Message.success("操作成功");
    } else {
      Message.error("创建失败: " + res.message);
    }
  });
}
// 个人导出
export function exportMsg(id) {
  exportMessage(id).then(res => {
    Message.success("操作成功");
    // 表格 application/xlsx，压缩包为 application/zip等，这里是pdf类型
    const pdfUrl = window.URL.createObjectURL(new Blob([res], { type: "application/pdf" }));
    const fileName = "PDF文件下载"; // 下载文件的名字
    if (typeof window.navigator.msSaveBlob !== "undefined") {
      window.navigator.msSaveBlob(pdfUrl, fileName);
    } else {
      const link = document.createElement("a");
      link.href = pdfUrl;
      link.setAttribute("download", fileName);
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link); // 下载完成移除元素
      window.URL.revokeObjectURL(pdfUrl); // 释放掉blob对象
    }
  });
}

// 打电话
export function getCall(id) {
  handleCall(id).then(res => {
    if (res.code === 200) {
      Message.success("呼叫成功");
    } else {
      Message.error("呼叫失败: " + res.message);
    }
  });
}
